package com.healthcloud.service.impl;

import java.util.ArrayList;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.healthcloud.dao.GeneticHistoryMapper;
import com.healthcloud.entity.GeneticHistory;
import com.healthcloud.service.GeneticHistoryService;

/**
 * Created by XYC on 2015/7/17.
 */
@Service
public class GeneticHistoryServiceImpl implements GeneticHistoryService {

    @Autowired
    private GeneticHistoryMapper geneticHistoryMapper;

    @Override
    public GeneticHistory saveOrUpdata(GeneticHistory geneticHistory) {
        ArrayList<GeneticHistory> geneticHistories=findByIdCard(geneticHistory);
        if(geneticHistories.isEmpty()){
            geneticHistory.setCreatedTime(new Date());
            geneticHistory.setUpdatedTime(new Date());
            geneticHistoryMapper.save(geneticHistory);
        }else{
            geneticHistory.setId(geneticHistories.get(0).getId());
            geneticHistory.setUpdatedTime(new Date());
            geneticHistory.setCreatedTime(geneticHistories.get(0).getUpdatedTime());
            geneticHistoryMapper.update(geneticHistory);
        }
        return geneticHistory;
    }

    @Override
    public ArrayList<GeneticHistory> findByIdCard(GeneticHistory geneticHistory) {
        GeneticHistory geneticHistory1 = new GeneticHistory();
        geneticHistory1.setIdCard(geneticHistory.getIdCard());
        return findByEntity(geneticHistory1);
    }

    @Override
    public ArrayList<GeneticHistory> findByEntity(GeneticHistory geneticHistory) {
        return geneticHistoryMapper.findByEntityWithOutPage(geneticHistory);
    }
}
